// pages/page/huodong/29_9.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    beginId: 0,
    content: [],
    showGoBackToTop: false,
    scrollTop: 0,
    isNoMore: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDataFromService();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("下拉刷新")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("上拉触底")
    var beginIdSize = this.data.content.length;
    this.setData({
      beginId: beginIdSize,

    });
    console.log("beginId--->" + this.data.beginId);
    this.getDataFromService();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 滑动到底部
   */
  scrollBottomListener: function (event) {
    this.onReachBottom();
  },
  /**
   * 返回顶部
   */
  goToTop: function (event) {
    this.setData({
      scrollTop: 0,
    })
  },
  /**
   * 滑动的时候监听
   */
  pageScrolllistener: function (event) {
    console.log(event);
    if (event.detail.scrollTop <= 20
      && this.data.showGoBackToTop == true
    ) {
      this.setData({
        showGoBackToTop: false,
      });


    } else
      if (this.data.showGoBackToTop == false) {
        this.setData({
          showGoBackToTop: true,
        });

      }
  },
  /**
   * 从服务器中获取数据
   */
  getDataFromService: function () {
    var that = this;

    wx: wx.request({
      url: "http://120.55.137.143:54321/service/teabubble/shop_paopao_goods?methods=getCPPGoodsList",
      data: {
        "beginId": that.data.beginId,
        "count": 20,
        "status": 2,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.content.length < 20) {
          that.setData({
            isNoMore: true,
          });
        }
        var contentList = that.data.content.concat(res.data.content);

        that.setData({
          content: contentList,
        });
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  }
})